Skip to content

Conversation

@chiragramani
Copy link

@chiragramani chiragramani commented Sep 17, 2025

This PR introduces two new instrumentation flags and plumbs them through to IRGen:

  1. -ir-profile-generate - enable IR-level instrumentation.

  2. -cs-profile-generate - enable context-sensitive IR-level instrumentation.

Context: https://forums.swift.org/t/ir-level-pgo-instrumentation-in-swift/82123

Open Questions (Reviewer Input Requested)

  1. Naming:
    Is -ir-profile-generate a good flag name?
    -cs-profile-generate pairs nicely with Clang’s -fcs-profile-generate. However, -ir-profile-generate feels closer to Clang's -fprofile-generate but -profile-generate already exists in Swift as a frontend level and not IR level. Should it stay as is, or is there a clearer alternative?

  2. PR separation strategy:
    I also updated the auto-generated Options.swift file in this PR, I am aware its not supposed to manually updated and I have a Swift-side PR open here: Add IRPGO and CSIRPGO options to Swift swift#84335
    .
    Should I first land a separate PR in Swift adding only the new options, and then follow up with this PR for the Driver + IRGen functionality? My current assumption is that splitting them would help unblock this PR. Is that correct?

@chiragramani chiragramani changed the title Add ir and cs instrumentation options Adds IR level PGO Instrumentation options Sep 17, 2025
Copy link

@ellishg ellishg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you plan to add support for -ir-profile-use and -cs-profile-use?

Comment on lines -261 to -263
if parsedOptions.hasArgument(.profileGenerate) {
commandLine.appendFlag("-fprofile-generate")
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like a bug to me. As I understand, Swift's -profile-generate flag does front-end instrumentation, and is different from Clang's -fprofile-generate.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this behavior is existing in swift-driver today, and I’m a bit wary of changing it here because there may be tests and downstream flows that rely on it. This PR is primarily adding the new pieces, that said, if you feel it’s worth addressing this legacy behavior in the same PR, please let me know and I can look into it.

@artemcm
Copy link
Contributor

artemcm commented Sep 17, 2025

Just a friendly heads-up that new changes need to be added with this process:
https://github.com/swiftlang/swift-driver?tab=readme-ov-file#rebuilding-optionsswift

@chiragramani
Copy link
Author

Do you plan to add support for -ir-profile-use and -cs-profile-use?

Yes, I’ve added -ir-profile-use in the Swift repo, which, in line with Clang, configures PGOOptions correctly. This PR isn’t fully up to date yet, but once the Swift PR lands, I’ll make sure to update this one as well.

@chiragramani
Copy link
Author

Just a friendly heads-up that new changes need to be added with this process: https://github.com/swiftlang/swift-driver?tab=readme-ov-file#rebuilding-optionsswift

Thank you for the heads-up! I’ll take a look and make sure to follow that process.

drodriguez pushed a commit to swiftlang/swift that referenced this pull request Oct 10, 2025
This PR introduces three new instrumentation flags and plumbs them
through to IRGen:

1. `-ir-profile-generate` - enable IR-level instrumentation.
2. `-cs-profile-generate` - enable context-sensitive IR-level
instrumentation.
3. `-ir-profile-use` - IR-level PGO input profdata file to enable
profile-guided optimization (both IRPGO and CSIRPGO)

**Context:**
https://forums.swift.org/t/ir-level-pgo-instrumentation-in-swift/82123

**Swift-driver PR:** swiftlang/swift-driver#1992

**Tests and validation:**
This PR includes ir level verification tests, also checks few edge-cases
when `-ir-profile-use` supplied profile is either missing or is an
invalid IR profile.

However, for argument validation, linking, and generating IR profiles
that can later be consumed by -cs-profile-generate, I’ll need
corresponding swift-driver changes. Those changes are being tracked in
swiftlang/swift-driver#1992
@chiragramani chiragramani marked this pull request as ready for review October 20, 2025 17:34
dendiz pushed a commit to dendiz/swift that referenced this pull request Oct 21, 2025
This PR introduces three new instrumentation flags and plumbs them
through to IRGen:

1. `-ir-profile-generate` - enable IR-level instrumentation.
2. `-cs-profile-generate` - enable context-sensitive IR-level
instrumentation.
3. `-ir-profile-use` - IR-level PGO input profdata file to enable
profile-guided optimization (both IRPGO and CSIRPGO)

**Context:**
https://forums.swift.org/t/ir-level-pgo-instrumentation-in-swift/82123

**Swift-driver PR:** swiftlang/swift-driver#1992

**Tests and validation:**
This PR includes ir level verification tests, also checks few edge-cases
when `-ir-profile-use` supplied profile is either missing or is an
invalid IR profile.

However, for argument validation, linking, and generating IR profiles
that can later be consumed by -cs-profile-generate, I’ll need
corresponding swift-driver changes. Those changes are being tracked in
swiftlang/swift-driver#1992
@chiragramani
Copy link
Author

Just a friendly heads-up that new changes need to be added with this process: https://github.com/swiftlang/swift-driver?tab=readme-ov-file#rebuilding-optionsswift

Thank you for the heads-up! I’ll take a look and make sure to follow that process.

Hey @artemcm , I have updated the PR post following https://github.com/swiftlang/swift-driver?tab=readme-ov-file#rebuilding-optionsswift. Please let me know if you have any other suggestions.

speednoisemovement pushed a commit to speednoisemovement/swift that referenced this pull request Oct 29, 2025
This PR introduces three new instrumentation flags and plumbs them
through to IRGen:

1. `-ir-profile-generate` - enable IR-level instrumentation.
2. `-cs-profile-generate` - enable context-sensitive IR-level
instrumentation.
3. `-ir-profile-use` - IR-level PGO input profdata file to enable
profile-guided optimization (both IRPGO and CSIRPGO)

**Context:**
https://forums.swift.org/t/ir-level-pgo-instrumentation-in-swift/82123

**Swift-driver PR:** swiftlang/swift-driver#1992

**Tests and validation:**
This PR includes ir level verification tests, also checks few edge-cases
when `-ir-profile-use` supplied profile is either missing or is an
invalid IR profile.

However, for argument validation, linking, and generating IR profiles
that can later be consumed by -cs-profile-generate, I’ll need
corresponding swift-driver changes. Those changes are being tracked in
swiftlang/swift-driver#1992
@chiragramani
Copy link
Author

Hey @artemcm / @cachemeifyoucan , when you get a moment, could you take a look at this PR please? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants